package com.huage_06.lesson_04;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapTest02 {
    public static void main(String[] args) {
        HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();

        //创建ArrayList元素
        ArrayList<String> array1 = new ArrayList<String>();
        array1.add("诸葛亮");
        array1.add("赵云");

        ArrayList<String> array2 = new ArrayList<String>();
        array2.add("唐僧");
        array2.add("孙悟空");

        ArrayList<String> array3 = new ArrayList<String>();
        array3.add("武松");
        array3.add("鲁智深");

        //存储
        map.put("三国演义",array1);
        map.put("嘻游记",array2);
        map.put("水浒传",array3);

        //HashMap遍历方式一 获取键值集合
        Set<String> keySet = map.keySet();
        for(String key : keySet){
            ArrayList<String> array = map.get(key);
            System.out.println(key+","+array);
        }
        System.out.println("-------");

        //HashMap遍历方式二 键值对对象获取键和值
        Set<Map.Entry<String, ArrayList<String>>> entries = map.entrySet();
        for (Map.Entry<String, ArrayList<String>> arrayListEntry : entries){
            String key = arrayListEntry.getKey();
            ArrayList<String> array = arrayListEntry.getValue();
            System.out.println(key+","+array);
        }

    }
}
